package ishacrm.client;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class IshaCheckinMockup implements EntryPoint {
	
	Map<String, HTMLPanel> viewMap = new HashMap<String, HTMLPanel>();
	
	public void onModuleLoad() {
		final MasterLayout masterLayout = new MasterLayout();
		RootLayoutPanel.get().add(masterLayout);
						
		//add history listener
		History.addValueChangeHandler(new ValueChangeHandler<String>() {
			
			@Override
			public void onValueChange(ValueChangeEvent<String> event) {
				String token = event.getValue();
				render(masterLayout, token);						
			}
		});
		
		String token = History.getToken();	
		render(masterLayout, token);
	}
	
	private void render(MasterLayout masterLayout, String token) {
		HTMLPanel viewhHtmlPanel = ViewImplFactory.get(token);
		
		masterLayout.contentHtmlPanel.clear();
		masterLayout.contentHtmlPanel.add(viewhHtmlPanel);
		
		masterLayout.setActiveNavLink(token);
	}		
}
